package com.data_structure_algorithm.data_structure.queue;

/**
 * @author 何章怀晓 hezhanghuaixiao
 * @version V1.0
 * @desc  队列
 */
public class Queue {

  int max;

  int[] queue;

  int head = -1;

  int tail = -1;

  public Queue(int max) {
    this.max = max;
    queue = new int[max];
  }

  public void add(int a) {
    if (isFull()) {
      System.out.println("容量已满");
      return;
    }
    //注意：这里需先++，否则第二个添加的元素会替换首元素，总体少加一个
    queue[++tail] = a;


  }

  public void print() {
    for (int i = 0; i < queue.length; i++) {
      System.out.println(queue[i]);
    }
  }


  public int get() {
    if (isEmpty()) {
      throw new RuntimeException("队列为空");
    }

    //获取数据尾不变 头往后移动
    return queue[++head];
  }



  private boolean isFull() {
    return max - 1 == tail;
  }

  private boolean isEmpty() {
    //不论初始还是取完，这两个指针都相等，初始均为-1，取完均为max-1
    //遗留问题
    return tail == head;
  }

  public static void main(String[] args) {
   /* Queue queue = new Queue(3);
    System.out.println("开始存储");
    queue.add(10);
    queue.add(11);
    queue.add(12);
    queue.add(13);
    queue.print();*/

    System.out.println(4%3);

  }


}
